{% extends 'bookmanage/base.html' %}

{% block content %}
    <script>
        $(".the_list").on("click", function () {
            $(this).addClass("active").siblings().removeClass("active")
        })
    </script>

    <div class="panel panel-default">
        <!-- Default panel contents -->
        <div class="panel-heading">图书列表</div>
        <div class="panel-body pull-right">
            <a class="btn btn-primary" href="{% url 'book_add' %}" role="button">新增</a>
        </div>

        <!-- Table -->
        <table class="table table-bordered table-hover">
            <tr>
                <th>id</th>
                <th>书名</th>
                <th>价格</th>
                <th>出版时间</th>
                <th>作者</th>
                <th>出版社</th>
                <th>编辑</th>
            </tr>
            {% for book in book_list %}
                <tr>
                    <td>{{ forloop.counter }}</td>
                    <td>{{ book.name }}</td>
                    <td>{{ book.price }}</td>
                    <td>{{ book.create_time|date:"Y-m-d" }}</td>
                    <td>
                        {{ book.auther_set.all }}
                        {% for auther in book.auther.all %}
                            {{ auther.name }}
                        {% endfor %}
                    </td>
                    <td>{{ book.publish.name }}</td>
                    <td>
                        <a href="{% url "book_change" id=book.id %}">修改</a>
                        <a href="{% url 'book_delete' id=book.id %}">删除</a>
                    </td>
                </tr>
            {% empty %}
                <tr>
                    <td colspan="7">暂无最新数据，请先添加</td>
                </tr>
            {% endfor %}
        </table>
    </div>

    <script>
        $(".book_list").addClass("active")
        $(".auth_list").removeClass("active")
        $(".pub_list").removeClass("active")
    </script>

{% endblock %}
